import {
    Block,
    BlockComponentTypes,
    BlockPermutation,
    ItemStack,
} from "@minecraft/server";

export interface BlockedInCombatBlockData {
    permutation?: BlockPermutation;
    blockId?: string;
    buildBlock?: () => BlockPermutation;
    afterSet?: (block: Block) => void;
    prob: number;
}

export const BlockedInCombatBlocks: BlockedInCombatBlockData[] = [
    { blockId: "oak_planks", prob: 1.2 },
    { blockId: "cobblestone", prob: 1.2 },
    { blockId: "stone", prob: 1.2 },
    { blockId: "tnt", prob: 0.3 },
    { blockId: "purpur_block", prob: 1 },
    { blockId: "hay_block", prob: 1 },
    { blockId: "gold_ore", prob: 1.2 },
    { blockId: "iron_ore", prob: 1.2 },
    { blockId: "diamond_ore", prob: 1.1 },
    { blockId: "coal_ore", prob: 1.1 },
    { blockId: "lapis_ore", prob: 1.1 },
    { blockId: "redstone_ore", prob: 1.1 },
    { blockId: "copper_ore", prob: 1.1 },
    { blockId: "ancient_debris", prob: 1 },
    { blockId: "oak_log", prob: 1.2 },
    { blockId: "melon_block", prob: 1.2 },
    { blockId: "anvil", prob: 0.9 },
    { blockId: "brewing_stand", prob: 0.9 },
    { blockId: "furnace", prob: 0.8 },
    { blockId: "blast_furnace", prob: 0.9 },
    { blockId: "enchanting_table", prob: 0.8 },
    { blockId: "noteblock", prob: 0.7 },
    { blockId: "crafting_table", prob: 0.9 },
    { blockId: "bookshelf", prob: 1 },
    {
        buildBlock: () =>
            BlockPermutation.resolve("cauldron", { fill_level: 3 }),
        prob: 0.8,
    },
    { blockId: "oak_leaves", prob: 1.1 },
    { blockId: "web", prob: 1 },
    { blockId: "gravel", prob: 1 }, //沙砾
    { blockId: "obsidian", prob: 1 }, //黑曜石
    { blockId: "soul_sand", prob: 1 }, //灵魂沙
    { blockId: "glass", prob: 1 }, //玻璃
    { blockId: "slime", prob: 1 }, //史莱姆
    { blockId: "snow", prob: 1 }, //雪
    {
        blockId: "barrel",
        prob: 0.4,
        afterSet(block) {
            const container = block.getComponent(
                BlockComponentTypes.Inventory
            )?.container;
            if (!container) return;
            const items = [
                new ItemStack("netherite_upgrade_smithing_template", 1),
                new ItemStack("blaze_rod", 2),
                new ItemStack("nether_wart", 2),
            ];
            items.forEach((item) => container.addItem(item));
        },
    },
];
